<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../lib/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../lib/vue-router-3.0.1.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<router-link to="/account">Account</router-link>
			<router-view></router-view>
			
			
		</div>
		<template id="tmp1">
			<div>
				<h1>这是account组件</h1>
				<router-link to="/account/login">登录</router-link>
				<router-link to="/account/register">注册</router-link>
				<!-- 这里还需要放一个router-view -->
				<router-view></router-view>
			</div>
		</template>
		
		<script type="text/javascript">
			//组件模板对象
			var account = {
				template:'#tmp1'
			}
			var login = {
				template:'<h1>登录组件</h1>'
			}
			var register = {
				template:'<h1>注册组件</h1>'
			}
			var router = new VueRouter({
				routes:[
					{
						path:'/account',
						component:account,
						/* 通过children属性实现子路由的嵌套 ,注意子路由path前面不要加/*/
						children:[
							{path:'login',component:login},
							{path:'register',component:register}
						]
						},
					/* {path:'/account/login',component:login},
					{path:'/account/register',component:register}, */
				]
			})
			
			var vm = new Vue({
				el:'#app',
				data:{},
				methods:{},
				router:router,
				watch:{
					/* 监视路由事件的改变 */
					'$route.path':function(newVal,oldVal){
						if(newVal === '/account/login'){
							console.log("欢迎")
						}
					}
				}
			})
		</script>
	</body>
</html>
